﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class SpecialNewsDetail : YuanlinUserControl,
        IReplyConverter<SpecialNewsReply, GetOperation>
    {
        protected Repeater list;
        private SpecialNews news;

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            if (!Page.IsPostBack)
            {
                requestBinders.Add(RequestHelper.BuildGetSpecialNewsRequest(this));
            }
        }

        private void BindData()
        {
            ArrayList newsList = new ArrayList();

            if (news != null)
            {
                newsList.Add(news);

                news.Views.Value++;
                BusinessManager.UpdateSpecialNews(news);
            }

            this.list.DataSource = newsList;
            this.list.DataBind();
        }

        #region IReplyConverter<SpecialNewsReply,GetOperation> Members

        public void ConvertReply(SpecialNewsReply reply, GetOperation operation)
        {
            if (reply != null)
            {
                news = reply.Entity as SpecialNews;

                if (!Page.IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
